package com.woyowodaows.utils;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lzy.imagepicker.loader.ImageLoader;
import com.woyowodaows.R;
import com.woyowodaows.weight.GlideCircleTransform;

import java.io.File;


/**
 * Created by Administrator on 2017/9/16.
 */

public class GlideImageLoader implements ImageLoader {
    @Override
    public void displayImage(Activity activity, String path, ImageView imageView, int width, int height) {
        Glide.with(activity).load(Uri.fromFile(new File(path)))
                .placeholder(R.mipmap.default_image)
                .error(R.mipmap.default_image)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageView);

    }

    @Override
    public void displayImagePreview(Activity activity, String path, ImageView imageView, int width, int height) {

    }


    @Override
    public void clearMemoryCache() {

    }


    public static void loadImage(Context mContext, String path, ImageView imageView) {
        Glide.with(mContext)
                .load(path)
                .placeholder(R.mipmap.default_image)
                .error(R.mipmap.default_image)
                .into(imageView);

    }
    /**
     * 加载圆形图片
     * @param context
     * @param imageUrl
     * @param errorImageId
     * @param imageView
     */
    public static void displayHeadImage(Context context, String imageUrl,int errorImageId, ImageView imageView){
        Glide.with(context).load(imageUrl).asBitmap().centerCrop().skipMemoryCache(true).
                diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(errorImageId).
                error(errorImageId).
                transform(new GlideCircleTransform(context)).
                into(imageView);
    }
}
